<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-list-swipe.css" />

</head>

<body>
    <header id='header' class="aui-bar aui-bar-nav" style="background-color: #03a9f4">
        <a class="aui-pull-left aui-btn" onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="middle">
            返修件状态查询
        </div>
    </header>
    <div class="aui-content">

        <ul class="aui-list aui-form-list">

            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">产品条码</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="请扫描产品条码" id="barcode" value="" onclick="getIdSelector();">
                    </div>
                </div>
            </li>
        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;">

            <div style="background-color:white; height: 100%;width: 100%;">

                <ul class="ui-selectee" id="tbodyHtml">

                </ul>
            </div>
        </div>


</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="../script/aui-list-swipe.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var mrlCodeSel = "";
    var list = [];
    // apiready = function () {
    //     api.addEventListener({
    //         barcode: 'viewappear' 
    //     }, function(ret, err) {
    //         $('#barcode').val("");
    //         api.setFocus({
    //             inputId: 'barcode',
    //             focus: true,
    //         });
    //     });
    // }

    apiready = function () {

        $("#barcode").focus();
        idSelector = "barcode";


    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }




    //查询
    function doSearch() {
        //光标所在id
        var idSelector = "";
        var barcode = ""; //产品条码
        //产品条码
        var barcode = $("#barcode").val();
        if (barcode == null || barcode == undefined || barcode == "") {
            api.toast({
                msg: "请先选择/扫描 产品条码",
                duration: 3000
            });
            return;
        }
         api.showProgress({
                    title: '查询中...',
                });

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/repairStatusList";
        var data = {
            values: {
                barcode: barcode,
                appVersion: api.appVersion,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<li class='sortable ui-selectee ui-sortable' >";
                        html += "<ul class='aui-list aui-media-list ui-selectee' >";
                        html += "<li class='aui-list-item  ui-selectee'  >";

                        html += "<div class='aui-media-list-item-inner ui-selectee' >";
                        html += "<div class='aui-list-item-inner ui-selectee'  >";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>产品条码：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 20px;color:black;'>" + list[i].produBarcode + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>是否为返修件：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;'>" + list[i].ifRepair + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>当前所在工序：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;'>" + list[i].opCode + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>记录问题工序：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;'>" + (list[i].jlOpCode==null?"":list[i].jlOpCode) + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>返回工序：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;'>" + list[i].fxOpCode + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 85%;'>是否生成返修计划：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 2px;color:black;'>" + list[i].ifRePaird + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>返修类别：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;'>" + list[i].fxType + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>处理状态：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;'>" + (list[i].confirmState==null?"":list[i].confirmState)  + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>返修区确认结果：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;'>" + list[i].fjqStatus + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>是否已上线：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;'>" + list[i].gatherFlag + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;'>返修复检结果：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;'>" + list[i].fjStatus + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 85%;'>返修计划是否已完成：</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 2px;color:black;'>" + list[i].isRpFinish + "</div>";
                        html += "</div>";
                        var height = 30
                        if (list[i].fxRoute != null) {
                            var s = Math.ceil(list[i].fxRoute.length / 10);
                            console.log(s)
                            height += s * 10;
                        }
                        html += "<div class='aui-list-item-text ui-selectee' style='height: " + height + "px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;' >返修工艺路线：</div>";
                        if (list[i].fxRoute != null &&list[i].fxRoute!='') {
                            html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;background-color: #98FB98;' >" + list[i].fxRoute + "</div>";
                        } else {
                            html += "<div class='aui-list-item-inner ui-selectee'>" + '' + "</div>";
                        }

                        // html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        // html += "<div class='aui-list-item-label ui-selectee list-tr-title'  style='width: 60%;' >返修工艺路线：</div>";
                        // html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 40px;color:black;' >" + list[i].fxRoute + "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    // console.log("htmlhtml",html);
                    $api.html($api.byId("tbodyHtml"), html);
                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }else{
                api.hideProgress();
            }
        });
    }



    $("#barcode").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var sm = $(this).val();
        if (keycode == '13') {

            $("#barcode").val(sm);
            doSearch()
        }
    });


    //返回按钮
    function closeWin() {
        api.closeWin({});
    }


</script>

</html>